package com.xyhy.core.jackson.deser;

import java.io.IOException;
import java.util.Objects;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;

public class MoneyDeserializer extends StdDeserializer<Integer> {
  private static final long serialVersionUID = 1L;

  public MoneyDeserializer() {
    super(Integer.class);
  }

  @Override
  public Integer deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    if (Objects.nonNull(p.getText())) {
      try {
        return (int) (Float.valueOf(p.getText()) * 100);
      } catch (Exception e) {
        e.printStackTrace();
        return null;
      }
    }
    return null;
  }

}